<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <title>用户绑定</title>
    <link rel="stylesheet" href="/css/weui.css">
    <link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div class="weui-cells weui-cells_form">
    <div class="weui-cell">
      <div class="weui-cell__hd">
          <label for="userName" class="weui-label width-sm">姓名</label>
      </div>
      <div class="weui-cell__bd">
          <input class="weui-input" id="userName" placeholder="请输入姓名" maxlength="11">
      </div>
    </div>
    <div class="weui-cell weui-cell_vcode">
        <div class="weui-cell__hd">
            <label for="userTel" class="weui-label width-sm">手机号</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="userTel" type="tel" placeholder="请输入手机号" maxlength="11">
        </div>
        <div class="weui-cell__ft">
            <button class="weui-vcode-btn width-f110" id="getCode">获取验证码</button>
        </div>
    </div>
    <div class="weui-cell">
        <div class="weui-cell__hd">
            <label for="telCode" class="weui-label width-sm">验证码</label>
        </div>
        <div class="weui-cell__bd">
            <input class="weui-input" id="telCode" type="tel" placeholder="请输入验证码" maxlength="6">
        </div>
    </div>
</div>
<div class="weui-btn-area pt5">
    <a class="weui-btn weui-btn_primary" href="javascript:" id="submitBind">提交</a>
</div>
<div class="weui-toptips weui-toptips_warn js_tooltips"></div>
<script src="/js/zepto.min.js"></script>
<script src="/js/jquery.min.js"></script>
<!--
本页面表单验证规则 ['null;mobile', 'null;/^[0-9]{6}$/']：
手机号：不为空，正确格式
验证码：不为空，6位
-->
<script>
    (function ($) {
        $(function () {
            //获取验证码
            $('#getCode').on('click', function () {
                var _t = $(this);
                if (!_t.attr('disabled')) {
                    _t.attr('disabled', 'true');
                    var _userTel = $('#userTel');
                    var _userName=$('#userName');
                    if (1==1) {
                        var remain = 60;
                        _t.html(remain + '秒');
                        var timeRemain = setInterval(function () {
                            if (remain > 1) {
                                remain--;
                                _t.html(remain + '秒');
                            } else {
                                clearInterval(timeRemain);
                                _t.html('获取验证码').removeAttr('disabled');
                            }
                        }, 1000);
                        $.post("localhost/phone_code",{phone:_userTel,from:'wx'},function(result){
                            console.log(result)
                        });
                        // $.ajax({
                        //     url: "localhost/phone_code",
                        //     type: "POST",
                        //     contentType: 'application/json;charset=utf-8',
                        //     timeout: 1000,
                        //     data:{ phone: _userTel , from:'wx'},
                        //     success: function(data){
                        //       // if(data.code==500)alert(data.msg);
                        //       // if(data.code==-500)alert(data.msg);
                        //       // else{
                        //       //   alert(data.msg);
                        //         console.log(data);
                        //         // location.href = '2.setpass.html';
                        //       // }
                        //     },
                        //     error: function(xhr, type){
                        //       alert('Ajax error!')
                        //     }
                        //   });
                    } else {
                        _t.removeAttr('disabled');
                    }
                }
            });

            //提交
            $('#submitBind').on('click', function () {
                var _userTel = $('#userTel');
                var _telCode = $('#telCode');
                var _userName=$('#userName');
                if (1==1){
                  var _openid="<? echo $openid ;?>";
                  $.ajax({
                      url: "localhost/verifyLogin",
                      type: "POST",
                      contentType: 'application/json;charset=utf-8',
                      timeout: 1000,
                      data:{ openid: _openid , cellphone:_userTel,userName:_userName },
                      success: function(data){
                        if(data.code==500)alert(data.msg);
                        if(data.code==-500)alert(data.msg);
                        else{
                          alert(data.msg);
                          console.log('Submit Begin');
                          // location.href = '2.setpass.html';
                        }
                      },
                      error: function(xhr, type){
                        alert('Ajax error!');
                      }
                      })
                }
            });
        });
    })(Zepto);
</script>
</body>
</html>
